

$Behavior.marketplaceAdd = function()
{
    $('.js_mp_category_list').change(function()
    {
        var iParentId = parseInt(this.id.replace('js_mp_id_', ''));
		
        $('.js_mp_category_list').each(function()
        {
            if (parseInt(this.id.replace('js_mp_id_', '')) > iParentId)
            {
                $('#js_mp_holder_' + this.id.replace('js_mp_id_', '')).hide();				
				
                this.value = '';
            }
        });
		
        $('#js_mp_holder_' + $(this).val()).show();
    });	
}

function addStoreLink(){
    $("#store_links_holder").append('<input placeholder="Add your online store" type="text" name="val[store_link][]" value="" size="80" maxlength="100" /><br/>');
}

var isStoreDataStep = false;
function openStore(){
    if($("#store_id").val() == 0 && !isStoreDataStep){
        $("#open_store_step_info").hide();
        $("#open_store_step_store_data").show();
        $("#js_box_title").text("Store infomation");
        isStoreDataStep = true;
        return false;
    }
    return true;
}


/// Images loading
var iCurrentImage = 0;
var iTotalImages = 0;

$Behavior.calculateImages = function(){
    iCurrentImage = 0;
    iTotalImages = $(".image_preview").length - 1;
}
function imagePrevious(){
    if(iCurrentImage > 0){
        iCurrentImage--;
    }
    else{
        iCurrentImage = iTotalImages - 1;
    }
    $(".image_preview").hide();
    $("#image_preview_"+iCurrentImage).show();
    $("#image_link").val($("#image_preview_"+iCurrentImage).attr("src"));
}
function imageNext(){
    if(iCurrentImage < (iTotalImages - 1)){
        iCurrentImage++;
    }
    else{
        iCurrentImage = 0;
    }
    $(".image_preview").hide();
    $("#image_preview_"+iCurrentImage).show();
    $("#image_link").val($("#image_preview_"+iCurrentImage).attr("src"));
}

// Album creator
function createAlbum(albumName,alBumType){
    $.ajaxCall("marketplace.store.createAlbum","albumName="+albumName+"&albumType="+alBumType);
}

function createAlbumMessage(message,type){
    $("#album_create_form_message").text(message);
    if(type == ""){
        $("#album_create_form_message").addClass(type);
    }
    else{
        $("#album_create_form_message").attr('class','');
    }
}

function createAlbumSuccess(id,name){
    $("#album_select_panel > ul > li").removeClass("active");
    $("#album_select_panel > ul").append('<li class="active"><a ref="'+id+'" href="#" onclick="selectAlbum(this);return false;">'+name+'</a></li>');
    
    //$("#js_album_select").append('<option value="'+id+'">'+name+'</option>');
    $("#js_album_select").val(id);
    $("#js_album_select_link").text(name);
    $("#album_select_panel").hide();
    $("#album_name").val("");    
}
function selectAlbum(current){
    $("#album_select_panel > ul > li").removeClass("active");    
    $("#js_album_select").val($(current).attr('ref'));
    $("#js_album_select_link").text($(current).text());
    $("#album_select_panel").hide();
    $(current).parent().addClass("active");
}

function showListingStoreMap(id,place){
    $(".map_store").hide();
    var sId = 'js_map_listing_'+id;  
    if(place == 'feed'){
        sId = 'js_feed_map_listing_'+id; 
    }
    else{
        place = 'marketplace';
    }
    var obj = $('#'+sId);
    // Show reloading
    if(obj.css('display') == "none"){                       
        //$.ajaxCall("marketplace.store.showMap","id="+id);        
        $('html').click(function() {
            //Hide the menus if visible
            obj.hide();
        });
        obj.click(function(event){
            event.stopPropagation();
        });
        obj.parent().click(function(event){
            event.stopPropagation();
        });
        $('#'+sId).show();
        $.ajaxCall("marketplace.store.showMap","id="+id+'&place='+place);
    }
    else{
        obj.hide();
    }
}
function showListingMap(id,address,place){
    var sId = 'js_map_listing_content_'+id;    
    if(place == 'feed'){
        sId = 'js_feed_map_listing_content_'+id; 
    }
    var obj = $('#'+sId);
    obj.gmap3({
        map: {
            options: {
                 maxZoom: 14 
            }  
        },
        marker:{
            address: address,
            options: {
                icon: new google.maps.MarkerImage(
                    "http://icons.iconarchive.com/icons/icons-land/vista-map-markers/24/Map-Marker-Marker-Outside-Pink-icon.png",
                    new google.maps.Size(32, 37, "px", "px")
                    )
            }
        }
    },
    "autofit" );
    // Add icon
   
}